var target;
var pop_top;
var pop_left;
var cal_Day;
var oPopup = window.createPopup();


///////////// 일반 Calendar
function Calendar_Click(e) {
	cal_Day = e.title;
	if (cal_Day.length > 6) {
		var year  = cal_Day.substr(0,4);
		var month = cal_Day.substr(5,2); // 1월=0,12월=11
		var day   = cal_Day.substr(8,2);

		target.value = cal_Day
	}
	oPopup.hide();
}

function Calendar_D(obj) {
	var now = obj.value.split("-");
	target = obj;
	pop_top = document.body.clientTop + GetObjectTop(obj) - document.body.scrollTop;
	pop_left = document.body.clientLeft + GetObjectLeft(obj) -  document.body.scrollLeft;

	if (now.length == 3) {
		Show_cal(now[0],now[1],now[2]);					
	} else {
		now = new Date();
		Show_cal(now.getFullYear(), now.getMonth()+1, now.getDate());
	}
}

function Show_cal(sYear, sMonth, sDay) {
	var Months_day = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31)
	var Month_Val = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
	var intThisYear = new Number(), intThisMonth = new Number(), intThisDay = new Number();

	datToday = new Date();													// 현재 날자 설정
	
	intThisYear = parseInt(sYear,10);
	intThisMonth = parseInt(sMonth,10);
	intThisDay = parseInt(sDay,10);
	
	if (intThisYear == 0) intThisYear = datToday.getFullYear();				// 값이 없을 경우
	if (intThisMonth == 0) intThisMonth = parseInt(datToday.getMonth(),10)+1;	// 월 값은 실제값 보다 -1 한 값이 돼돌려 진다.
	if (intThisDay == 0) intThisDay = datToday.getDate();
	
	switch(intThisMonth) {
		case 1:
				intPrevYear = intThisYear -1;
				intPrevMonth = 12;
				intNextYear = intThisYear;
				intNextMonth = 2;
				break;
		case 12:
				intPrevYear = intThisYear;
				intPrevMonth = 11;
				intNextYear = intThisYear + 1;
				intNextMonth = 1;
				break;
		default:
				intPrevYear = intThisYear;
				intPrevMonth = parseInt(intThisMonth,10) - 1;
				intNextYear = intThisYear;
				intNextMonth = parseInt(intThisMonth,10) + 1;
				break;
	}
	intPPyear = intThisYear-1
	intNNyear = intThisYear+1

	NowThisYear = datToday.getFullYear();									// 현재 년
	NowThisMonth = datToday.getMonth()+1;									// 현재 월
	NowThisDay = datToday.getDate();											// 현재 일
	
	AfterdatToday = new Date(datToday.getFullYear(),datToday.getMonth(),datToday.getDate()+3); // 3일후
	AfterThisYear = AfterdatToday.getFullYear();								// 현재 년
	AfterThisMonth = AfterdatToday.getMonth()+1;								// 현재 월
	AfterThisDay = AfterdatToday.getDate();										// 현재 일
	AfterDay = AfterThisYear + day2(AfterThisMonth) + day2(AfterThisDay);			// 3일후

	datFirstDay = new Date(intThisYear, intThisMonth-1, 1);			// 현재 달의 1일로 날자 객체 생성(월은 0부터 11까지의 정수(1월부터 12월))
	intFirstWeekday = datFirstDay.getDay();									// 현재 달 1일의 요일을 구함 (0:일요일, 1:월요일)
	//intSecondWeekday = intFirstWeekday;
	intThirdWeekday = intFirstWeekday;
	
	datThisDay = new Date(intThisYear, intThisMonth, intThisDay);	// 넘어온 값의 날자 생성
	//intThisWeekday = datThisDay.getDay();										// 넘어온 날자의 주 요일
	
	intPrintDay = 1;																// 달의 시작 일자
	secondPrintDay = 1;
	thirdPrintDay = 1;

	Stop_Flag = 0
	
	if ((intThisYear % 4)==0) {												// 4년마다 1번이면 (사로나누어 떨어지면)
		if ((intThisYear % 100) == 0) {
			if ((intThisYear % 400) == 0) {
				Months_day[2] = 29;
			}
		} else {
			Months_day[2] = 29;
		}
	}
	intLastDay = Months_day[intThisMonth];						// 마지막 일자 구함

	Cal_HTML = "<html>";
	Cal_HTML += "<style type='text/css'><!-- td {color: #000000; font-size:11px;} --></style>";
	Cal_HTML += "<body>";
	Cal_HTML += "<form name='calendar'>";
	Cal_HTML += "<table id=Cal_Table border=0 bgcolor='#f4f4f4' cellpadding=1 cellspacing=1 width=100% onmouseover='parent.doOver(window.event.srcElement)' onmouseout='parent.doOut(window.event.srcElement)' style='font-size : 12;font-family:굴림;'>";
	Cal_HTML += "<tr height='30' align=center bgcolor='#f4f4f4'>";
	Cal_HTML += "<td colspan=7 align=center>";
	Cal_HTML += "	<select name='selYear' STYLE='font-size:11;' OnChange='parent.fnChangeYearD(calendar.selYear.value, calendar.selMonth.value, "+intThisDay+")';>";
	for (var optYear=(intThisYear-2); optYear<(intThisYear+2); optYear++) {
		Cal_HTML += "		<option value='"+optYear+"' ";
		if (optYear == intThisYear) Cal_HTML += " selected>\n";
		else Cal_HTML += ">\n";
		Cal_HTML += optYear+"</option>\n";
	}
	Cal_HTML += "	</select>";
	Cal_HTML += "&nbsp;&nbsp;&nbsp;<a style='cursor:hand;' OnClick='parent.Show_cal("+intPrevYear+","+intPrevMonth+","+intThisDay+");'><=</a> ";
	Cal_HTML += "<select name='selMonth' STYLE='font-size:11;' OnChange='parent.fnChangeYearD(calendar.selYear.value, calendar.selMonth.value, "+intThisDay+")';>";
	for (var i=1; i<13; i++) {	
		Cal_HTML += "		<option value='"+Month_Val[i-1]+"' ";
		if (intThisMonth == parseInt(Month_Val[i-1],10)) Cal_HTML += " selected>\n";
		else Cal_HTML += ">\n";
		Cal_HTML += Month_Val[i-1]+"</option>\n";
	}
	Cal_HTML += "	</select>&nbsp;";
	Cal_HTML += "<a style='cursor:hand;' OnClick='parent.Show_cal("+intNextYear+","+intNextMonth+","+intThisDay+");'>=></a>";
	Cal_HTML += "</td></tr>";
	Cal_HTML += "<tr align=center bgcolor='#d4e6f4' style='color:#2065DA;' height='20'>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=red>Sun</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Mon</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Tue</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Wed</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Thu</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Fri</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=blue>Sat</font></td>";
	Cal_HTML += "</tr>";
		
	for (intLoopWeek=1; intLoopWeek < 7; intLoopWeek++) {	// 주단위 루프 시작, 최대 6주
		Cal_HTML += "<tr height='17' align=right bgcolor='white'>"
		for (intLoopDay=1; intLoopDay <= 7; intLoopDay++) {	// 요일단위 루프 시작, 일요일 부터
			if (intThirdWeekday > 0) {											// 첫주 시작일이 1보다 크면
				Cal_HTML += "<td>";
				intThirdWeekday--;
			} else {
				if (thirdPrintDay > intLastDay) {								// 입력 날짝 월말보다 크다면
					Cal_HTML += "<td>";
				} else {																// 입력날짜가 현재월에 해당 되면
					Cal_HTML += "<td  align='center' onClick=parent.Calendar_Click(this); title="+intThisYear+'-'+day2(intThisMonth).toString()+'-'+day2(thirdPrintDay).toString()+" style=\"cursor:Hand;border:1px solid white;";

					if (intThisYear == NowThisYear && intThisMonth==NowThisMonth && thirdPrintDay==intThisDay) {
						Cal_HTML += "background-color:#C6F2ED;";
					}
					
					switch(intLoopDay) {
						case 1:															// 일요일이면 빨간 색으로
							Cal_HTML += "color:red;"
							break;
						case 7:
							Cal_HTML += "color:blue;"
							break;
						default:
							Cal_HTML += "color:black;"
							break;
					}
					Cal_HTML += "\">"+thirdPrintDay;
				}
				thirdPrintDay++;
				
				if (thirdPrintDay > intLastDay) {								// 만약 날짜 값이 월말 값보다 크면 루프문 탈출
					Stop_Flag = 1;
				}
			}
			Cal_HTML += "</td>";
		}
		Cal_HTML += "</tr>";
		if (Stop_Flag==1) break;
	}
	Cal_HTML += "</table></form></body></html>";

	var oPopBody = oPopup.document.body;
	oPopBody.style.backgroundColor = "lightyellow";
	oPopBody.style.border = "solid black 1px";
	oPopBody.innerHTML = Cal_HTML;

	var calHeight = oPopBody.document.all.Cal_Table.offsetHeight;
	//행이 6개 행인지, 5개인지 구분
	if (intLoopWeek == 6)
	{
		calHeight = 165;
	}
	else if (intLoopWeek == 5)
	{
		calHeight = 150;
	}
	else if (intLoopWeek == 4)
	{
		calHeight = 130;
	}

	oPopup.show(pop_left, (pop_top + target.offsetHeight+11), 170, calHeight, document.body);
}


//////////////////// 호텔용 Calendar
function Calendar_ClickHotel(e)
{

	cal_Day = e.title;
	if (cal_Day.length > 6) {
		var year  = cal_Day.substr(0,4);
		var month = cal_Day.substr(5,2); // 1월=0,12월=11
		var day   = cal_Day.substr(8,2);

		target.value = cal_Day
	}
		
	if(target.name == "checkin")
	{
		fnSetDateForNight();
	}
	else if (target.name == "checkout")
	{
		fnSetDateForCheckOut();
	}

	oPopup.hide();
}

function Calendar_ClickHotelOLD(e) {
	cal_Day = e.title;
	if (cal_Day.length > 6) {
		var year  = cal_Day.substr(0,4);
		var month = cal_Day.substr(5,2); // 1월=0,12월=11
		var day   = cal_Day.substr(8,2);
		var ngt = document.getElementById("nights").value;
		var cDate = addDay(year, parseInt(month,10), parseInt(day,10), ngt)
		var months = parseInt(cDate.getMonth())+1;
		var days = cDate.getDate();

		if(target.name=="checkin")
		{
			if(parseInt(months,10)<10)
			{
				months = "0" + months;
			}
			if(parseInt(days,10)<10)
			{
				days = "0" + days;
			}
			target.value = cal_Day
			document.getElementById("checkout").value = cDate.getFullYear() + "-" + months + "-" + days;
		}else{
			var ci_Dt = document.getElementById("checkin").value.replace(/\-/g,"");
			var co_Dt = cal_Day.replace(/\-/g,"");

			if(ci_Dt>=co_Dt)
			{
				alert("체크인날짜는 체크아웃날짜보다 빨라야 합니다.");
				return;
			}
			if(parseInt(getDayInterval(ci_Dt,co_Dt),10) > 20)
			{
				alert("Pleaes select 20 day under!!");
				return;
			}else{
				document.getElementById("nights").value= getDayInterval(ci_Dt,co_Dt);
				target.value = cal_Day
			}
		}
	}
	document.getElementById("searchflag").value = "N";
	oPopup.hide();
}

function Calendar_DHotel(obj) {
	var now = obj.value.split("-");
	target = obj;
	pop_top = document.body.clientTop + GetObjectTop(obj) - document.body.scrollTop;
	pop_left = document.body.clientLeft + GetObjectLeft(obj) -  document.body.scrollLeft;

	if (now.length == 3) {
		Show_calHotel(now[0],now[1],now[2]);					
	} else {
		now = new Date();
		Show_calHotel(now.getFullYear(), now.getMonth()+1, now.getDate());
	}
}

function Show_calHotel(sYear, sMonth, sDay) {
	var Months_day = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31)
	var Month_Val = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
	var intThisYear = new Number(), intThisMonth = new Number(), intThisDay = new Number();

	datToday = new Date();													// 현재 날자 설정
	
	intThisYear = parseInt(sYear,10);
	intThisMonth = parseInt(sMonth,10);
	intThisDay = parseInt(sDay,10);
	
	if (intThisYear == 0) intThisYear = datToday.getFullYear();				// 값이 없을 경우
	if (intThisMonth == 0) intThisMonth = parseInt(datToday.getMonth(),10)+1;	// 월 값은 실제값 보다 -1 한 값이 돼돌려 진다.
	if (intThisDay == 0) intThisDay = datToday.getDate();
	
	switch(intThisMonth) {
		case 1:
				intPrevYear = intThisYear -1;
				intPrevMonth = 12;
				intNextYear = intThisYear;
				intNextMonth = 2;
				break;
		case 12:
				intPrevYear = intThisYear;
				intPrevMonth = 11;
				intNextYear = intThisYear + 1;
				intNextMonth = 1;
				break;
		default:
				intPrevYear = intThisYear;
				intPrevMonth = parseInt(intThisMonth,10) - 1;
				intNextYear = intThisYear;
				intNextMonth = parseInt(intThisMonth,10) + 1;
				break;
	}
	intPPyear = intThisYear-1
	intNNyear = intThisYear+1

	NowThisYear = datToday.getFullYear();									// 현재 년
	NowThisMonth = datToday.getMonth()+1;									// 현재 월
	NowThisDay = datToday.getDate();											// 현재 일
	
//	AfterdatToday = new Date(datToday.getFullYear(),datToday.getMonth(),datToday.getDate()+3); // 3일후
	AfterdatToday = new Date(datToday.getFullYear(),datToday.getMonth(),datToday.getDate()); // 오늘
	AfterThisYear = AfterdatToday.getFullYear();								// 현재 년
	AfterThisMonth = AfterdatToday.getMonth()+1;								// 현재 월
	AfterThisDay = AfterdatToday.getDate();										// 현재 일
	AfterDay = AfterThisYear + day2(AfterThisMonth) + day2(AfterThisDay);			// 3일후

	datFirstDay = new Date(intThisYear, intThisMonth-1, 1);			// 현재 달의 1일로 날자 객체 생성(월은 0부터 11까지의 정수(1월부터 12월))
	intFirstWeekday = datFirstDay.getDay();									// 현재 달 1일의 요일을 구함 (0:일요일, 1:월요일)
	//intSecondWeekday = intFirstWeekday;
	intThirdWeekday = intFirstWeekday;
	
	datThisDay = new Date(intThisYear, intThisMonth, intThisDay);	// 넘어온 값의 날자 생성
	//intThisWeekday = datThisDay.getDay();										// 넘어온 날자의 주 요일
	
	intPrintDay = 1;																// 달의 시작 일자
	secondPrintDay = 1;
	thirdPrintDay = 1;

	Stop_Flag = 0
	
	if ((intThisYear % 4)==0) {												// 4년마다 1번이면 (사로나누어 떨어지면)
		if ((intThisYear % 100) == 0) {
			if ((intThisYear % 400) == 0) {
				Months_day[2] = 29;
			}
		} else {
			Months_day[2] = 29;
		}
	}
	intLastDay = Months_day[intThisMonth];						// 마지막 일자 구함

	Cal_HTML = "<html>";
	Cal_HTML += "<style type='text/css'><!-- td {color: #000000; font-size:11px;} --></style>";
	Cal_HTML += "<body>";
	Cal_HTML += "<form name='calendar'>";
	Cal_HTML += "<table id=Cal_Table border=0 bgcolor='#f4f4f4' cellpadding=1 cellspacing=1 width=100% onmouseover='parent.doOver(window.event.srcElement)' onmouseout='parent.doOut(window.event.srcElement)' style='font-size : 12;font-family:굴림;'>";
	Cal_HTML += "<tr height='30' align=center bgcolor='#f4f4f4'>";
	Cal_HTML += "<td colspan=7 align=center>";
	Cal_HTML += "	<select name='selYear' STYLE='font-size:11;' OnChange='parent.fnChangeYearDHotel(calendar.selYear.value, calendar.selMonth.value, "+intThisDay+")';>";
	for (var optYear=(intThisYear-2); optYear<(intThisYear+2); optYear++) {
		Cal_HTML += "		<option value='"+optYear+"' ";
		if (optYear == intThisYear) Cal_HTML += " selected>\n";
		else Cal_HTML += ">\n";
		Cal_HTML += optYear+"</option>\n";
	}
	Cal_HTML += "	</select>";
	Cal_HTML += "&nbsp;&nbsp;&nbsp;<a style='cursor:hand;' OnClick='parent.Show_calHotel("+intPrevYear+","+intPrevMonth+","+intThisDay+");'><=</a> ";
	Cal_HTML += "<select name='selMonth' STYLE='font-size:11;' OnChange='parent.fnChangeYearDHotel(calendar.selYear.value, calendar.selMonth.value, "+intThisDay+")';>";
	for (var i=1; i<13; i++) {	
		Cal_HTML += "		<option value='"+Month_Val[i-1]+"' ";
		if (intThisMonth == parseInt(Month_Val[i-1],10)) Cal_HTML += " selected>\n";
		else Cal_HTML += ">\n";
		Cal_HTML += Month_Val[i-1]+"</option>\n";
	}
	Cal_HTML += "	</select>&nbsp;";
	Cal_HTML += "<a style='cursor:hand;' OnClick='parent.Show_calHotel("+intNextYear+","+intNextMonth+","+intThisDay+");'>=></a>";
	Cal_HTML += "</td></tr>";
	Cal_HTML += "<tr align=center bgcolor='#d4e6f4' style='color:#2065DA;' height='20'>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=red>Sun</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Mon</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Tue</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Wed</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Thu</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Fri</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=blue>Sat</font></td>";
	Cal_HTML += "</tr>";
		
	for (intLoopWeek=1; intLoopWeek < 7; intLoopWeek++) {	// 주단위 루프 시작, 최대 6주
		Cal_HTML += "<tr height='17' align=right bgcolor='white'>"
		for (intLoopDay=1; intLoopDay <= 7; intLoopDay++) {	// 요일단위 루프 시작, 일요일 부터
			if (intThirdWeekday > 0) {											// 첫주 시작일이 1보다 크면
				Cal_HTML += "<td>";
				intThirdWeekday--;
			} else {
				if (thirdPrintDay > intLastDay) {								// 입력 날짝 월말보다 크다면
					Cal_HTML += "<td>";
				} else {																// 입력날짜가 현재월에 해당 되면
					if(intThisYear+day2(intThisMonth).toString()+day2(thirdPrintDay).toString() < AfterDay)
					{						//해당 날짜가 오늘보다 이전날짜이면
						Cal_HTML += "<td  align='center' onclick=\"javascript:alert('오늘 이후 날짜를 선택해 주세요!!');\" title="+intThisYear+day2(intThisMonth).toString()+day2(thirdPrintDay).toString()+" style=\"padding-top:4px;background:url(/azone/img/calendar/icon_x.gif) 5px 3px no-repeat; cursor:Hand;border:1px solid white";
						var iconX = "Y";
					}
					else
					{
						Cal_HTML += "<td  align='center' onClick=parent.Calendar_ClickHotel(this); title="+intThisYear+'-'+day2(intThisMonth).toString()+'-'+day2(thirdPrintDay).toString()+" style=\"cursor:Hand;border:1px solid white;";
						var iconX = "N";
					}


					if (intThisYear == NowThisYear && intThisMonth==NowThisMonth && thirdPrintDay==intThisDay) {
						Cal_HTML += "background-color:#C6F2ED;";
					}
					
					switch(intLoopDay) {
						case 1:															// 일요일이면 빨간 색으로
							Cal_HTML += "color:red;"
							break;
						case 7:
							Cal_HTML += "color:blue;"
							break;
						default:
							Cal_HTML += "color:black;"
							break;
					}
					Cal_HTML += "\">"+thirdPrintDay;
				}
				thirdPrintDay++;
				
				if (thirdPrintDay > intLastDay) {								// 만약 날짜 값이 월말 값보다 크면 루프문 탈출
					Stop_Flag = 1;
				}
			}
			Cal_HTML += "</td>";
		}
		Cal_HTML += "</tr>";
		if (Stop_Flag==1) break;
	}
	Cal_HTML += "<tr><td colspan='7' bgcolor=#FFFFFF height=80></td></tr>";
	Cal_HTML += "</table></form></body></html>";

	var oPopBody = oPopup.document.body;
	oPopBody.style.backgroundColor = "lightyellow";
	oPopBody.style.border = "solid black 1px";
	oPopBody.innerHTML = Cal_HTML;

	var calHeight = oPopBody.document.all.Cal_Table.offsetHeight;
	//행이 6개 행인지, 5개인지 구분
	calHeight = 184;

	oPopup.show(pop_left, (pop_top + target.offsetHeight+11), 170, calHeight, document.body);
}



//////////////////// Index용 Calendar
function Calendar_ClickIndex(e) {
	cal_Day = e.title;
	if (cal_Day.length > 6) {
		var year  = cal_Day.substr(0,4);
		var month = cal_Day.substr(5,2); // 1월=0,12월=11
		var day   = cal_Day.substr(8,2);
		var ngt = document.getElementById("ngtIndex").value;
		var cDate = addDay(year, parseInt(month,10), parseInt(day,10), ngt)
		var months = parseInt(cDate.getMonth())+1;
		var days = cDate.getDate();

		if(target.name=="ci_dtIndex")
		{
			if(parseInt(months,10)<10)
			{
				months = "0" + months;
			}
			if(parseInt(days,10)<10)
			{
				days = "0" + days;
			}
			target.value = cal_Day
			document.getElementById("co_dtIndex").value = cDate.getFullYear() + "-" + months + "-" + days;
		}else{
			var ci_Dt = document.getElementById("ci_dtIndex").value.replace(/\-/g,"");
			var co_Dt = cal_Day.replace(/\-/g,"");

			if(ci_Dt>=co_Dt)
			{
				alert("체크인날짜는 체크아웃날짜보다 빨라야 합니다.");
				return;
			}

			if(parseInt(getDayInterval(ci_Dt,co_Dt),10) > 20)
			{
				alert("Pleaes select 20 day under!!");
				return;
			}else{
				document.getElementById("ngtIndex").value= getDayInterval(ci_Dt,co_Dt);
				target.value = cal_Day
			}
		}
	}
	document.getElementById("searchflagIndex").value = "N";
	oPopup.hide();
}

function Calendar_DIndex(obj) {
	var now = obj.value.split("-");
	target = obj;
	pop_top = document.body.clientTop + GetObjectTop(obj) - document.body.scrollTop;
	pop_left = document.body.clientLeft + GetObjectLeft(obj) -  document.body.scrollLeft;

	if (now.length == 3) {
		Show_calIndex(now[0],now[1],now[2]);					
	} else {
		now = new Date();
		Show_calIndex(now.getFullYear(), now.getMonth()+1, now.getDate());
	}
}

function Show_calIndex(sYear, sMonth, sDay) {
	var Months_day = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31)
	var Month_Val = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
	var intThisYear = new Number(), intThisMonth = new Number(), intThisDay = new Number();

	datToday = new Date();													// 현재 날자 설정
	
	intThisYear = parseInt(sYear,10);
	intThisMonth = parseInt(sMonth,10);
	intThisDay = parseInt(sDay,10);
	
	if (intThisYear == 0) intThisYear = datToday.getFullYear();				// 값이 없을 경우
	if (intThisMonth == 0) intThisMonth = parseInt(datToday.getMonth(),10)+1;	// 월 값은 실제값 보다 -1 한 값이 돼돌려 진다.
	if (intThisDay == 0) intThisDay = datToday.getDate();
	
	switch(intThisMonth) {
		case 1:
				intPrevYear = intThisYear -1;
				intPrevMonth = 12;
				intNextYear = intThisYear;
				intNextMonth = 2;
				break;
		case 12:
				intPrevYear = intThisYear;
				intPrevMonth = 11;
				intNextYear = intThisYear + 1;
				intNextMonth = 1;
				break;
		default:
				intPrevYear = intThisYear;
				intPrevMonth = parseInt(intThisMonth,10) - 1;
				intNextYear = intThisYear;
				intNextMonth = parseInt(intThisMonth,10) + 1;
				break;
	}
	intPPyear = intThisYear-1
	intNNyear = intThisYear+1

	NowThisYear = datToday.getFullYear();									// 현재 년
	NowThisMonth = datToday.getMonth()+1;									// 현재 월
	NowThisDay = datToday.getDate();											// 현재 일
	
	AfterdatToday = new Date(datToday.getFullYear(),datToday.getMonth(),datToday.getDate()); // 3일후
	AfterThisYear = AfterdatToday.getFullYear();								// 현재 년
	AfterThisMonth = AfterdatToday.getMonth()+1;								// 현재 월
	AfterThisDay = AfterdatToday.getDate();										// 현재 일
	AfterDay = AfterThisYear + day2(AfterThisMonth) + day2(AfterThisDay);			// 3일후

	datFirstDay = new Date(intThisYear, intThisMonth-1, 1);			// 현재 달의 1일로 날자 객체 생성(월은 0부터 11까지의 정수(1월부터 12월))
	intFirstWeekday = datFirstDay.getDay();									// 현재 달 1일의 요일을 구함 (0:일요일, 1:월요일)
	//intSecondWeekday = intFirstWeekday;
	intThirdWeekday = intFirstWeekday;
	
	datThisDay = new Date(intThisYear, intThisMonth, intThisDay);	// 넘어온 값의 날자 생성
	//intThisWeekday = datThisDay.getDay();										// 넘어온 날자의 주 요일
	
	intPrintDay = 1;																// 달의 시작 일자
	secondPrintDay = 1;
	thirdPrintDay = 1;

	Stop_Flag = 0
	
	if ((intThisYear % 4)==0) {												// 4년마다 1번이면 (사로나누어 떨어지면)
		if ((intThisYear % 100) == 0) {
			if ((intThisYear % 400) == 0) {
				Months_day[2] = 29;
			}
		} else {
			Months_day[2] = 29;
		}
	}
	intLastDay = Months_day[intThisMonth];						// 마지막 일자 구함

	Cal_HTML = "<html>";
	Cal_HTML += "<style type='text/css'><!-- td {color: #000000; font-size:11px;} --></style>";
	Cal_HTML += "<body>";
	Cal_HTML += "<form name='calendar'>";
	Cal_HTML += "<table id=Cal_TableIndex border=0 bgcolor='#f4f4f4' cellpadding=1 cellspacing=1 width=100% onmouseover='parent.doOver(window.event.srcElement)' onmouseout='parent.doOut(window.event.srcElement)' style='font-size : 12;font-family:굴림;'>";
	Cal_HTML += "<tr height='30' align=center bgcolor='#f4f4f4'>";
	Cal_HTML += "<td colspan=7 align=center>";
	Cal_HTML += "	<select name='selYear' STYLE='font-size:11;' OnChange='parent.fnChangeYearDIndex(calendar.selYear.value, calendar.selMonth.value, "+intThisDay+")';>";
	for (var optYear=(intThisYear-2); optYear<(intThisYear+2); optYear++) {
		Cal_HTML += "		<option value='"+optYear+"' ";
		if (optYear == intThisYear) Cal_HTML += " selected>\n";
		else Cal_HTML += ">\n";
		Cal_HTML += optYear+"</option>\n";
	}
	Cal_HTML += "	</select>";
	Cal_HTML += "&nbsp;&nbsp;&nbsp;<a style='cursor:hand;' OnClick='parent.Show_calIndex("+intPrevYear+","+intPrevMonth+","+intThisDay+");'><img src='/azone/img/calendar/bt_schedule_pre.gif'></a> ";
	Cal_HTML += "<select name='selMonth' STYLE='font-size:11;' OnChange='parent.fnChangeYearDIndex(calendar.selYear.value, calendar.selMonth.value, "+intThisDay+")';>";
	for (var i=1; i<13; i++) {	
		Cal_HTML += "		<option value='"+Month_Val[i-1]+"' ";
		if (intThisMonth == parseInt(Month_Val[i-1],10)) Cal_HTML += " selected>\n";
		else Cal_HTML += ">\n";
		Cal_HTML += Month_Val[i-1]+"</option>\n";
	}
	Cal_HTML += "	</select>&nbsp;";
	Cal_HTML += "<a style='cursor:hand;' OnClick='parent.Show_calIndex("+intNextYear+","+intNextMonth+","+intThisDay+");'><img src='/azone/img/calendar/bt_schedule_next.gif'></a>";
	Cal_HTML += "</td></tr>";
	Cal_HTML += "<tr align=center bgcolor='#d4e6f4' style='color:#2065DA;' height='20'>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=red>Sun</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Mon</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Tue</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Wed</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Thu</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=black>Fri</font></td>";
	Cal_HTML += "	<td style='padding-top:3px;' width='24'><font color=blue>Sat</font></td>";
	Cal_HTML += "</tr>";
		
	for (intLoopWeek=1; intLoopWeek < 7; intLoopWeek++) {	// 주단위 루프 시작, 최대 6주
		Cal_HTML += "<tr height='17' align=right bgcolor='white'>"
		for (intLoopDay=1; intLoopDay <= 7; intLoopDay++) {	// 요일단위 루프 시작, 일요일 부터
			if (intThirdWeekday > 0) {											// 첫주 시작일이 1보다 크면
				Cal_HTML += "<td>";
				intThirdWeekday--;
			} else {
				if (thirdPrintDay > intLastDay) {								// 입력 날짝 월말보다 크다면
					Cal_HTML += "<td>";
				} else {																// 입력날짜가 현재월에 해당 되면
					if(intThisYear+day2(intThisMonth).toString()+day2(thirdPrintDay).toString() < AfterDay)
					{						//해당 날짜가 오늘보다 이전날짜이면
						Cal_HTML += "<td  align='center' onclick=\"javascript:alert('오늘 이후 날짜를 선택해 주세요!!');\" title="+intThisYear+day2(intThisMonth).toString()+day2(thirdPrintDay).toString()+" style=\"padding-top:4px;background:url(/azone/img/calendar/icon_x.gif) 5px 3px no-repeat; cursor:Hand;border:1px solid white";
						var iconX = "Y";
					}
					else
					{
						Cal_HTML += "<td  align='center' onClick=parent.Calendar_ClickIndex(this); title="+intThisYear+'-'+day2(intThisMonth).toString()+'-'+day2(thirdPrintDay).toString()+" style=\"cursor:Hand;border:1px solid white;";
						var iconX = "N";
					}


					if (intThisYear == NowThisYear && intThisMonth==NowThisMonth && thirdPrintDay==intThisDay) {
						Cal_HTML += "background-color:#C6F2ED;";
					}
					
					switch(intLoopDay) {
						case 1:															// 일요일이면 빨간 색으로
							Cal_HTML += "color:red;"
							break;
						case 7:
							Cal_HTML += "color:blue;"
							break;
						default:
							Cal_HTML += "color:black;"
							break;
					}
					Cal_HTML += "\">"+thirdPrintDay;
				}
				thirdPrintDay++;
				
				if (thirdPrintDay > intLastDay) {								// 만약 날짜 값이 월말 값보다 크면 루프문 탈출
					Stop_Flag = 1;
				}
			}
			Cal_HTML += "</td>";
		}
		Cal_HTML += "</tr>";
		if (Stop_Flag==1) break;
	}
	Cal_HTML += "</table></form></body></html>";

	var oPopBody = oPopup.document.body;
	oPopBody.style.backgroundColor = "lightyellow";
	oPopBody.style.border = "solid black 1px";
	oPopBody.innerHTML = Cal_HTML;

	var calHeight = oPopBody.document.all.Cal_TableIndex.offsetHeight;
	//행이 6개 행인지, 5개인지 구분
	if (intLoopWeek == 6 && iconX == "Y")
	{
		calHeight = 187;
	}
	else if (intLoopWeek == 6 && iconX == "N")
	{
		calHeight = 165;
	}
	else if (intLoopWeek == 5)
	{
		calHeight = 150;
	}
	else if (intLoopWeek == 4)
	{
		calHeight = 130;
	}

	
	oPopup.show(pop_left, (pop_top + target.offsetHeight), 170, calHeight, document.body);
}




////// 공통모듈 ////////

function doOver(el) {
	cal_Day = el.title;

	if (cal_Day.length > 7) {
		el.style.borderColor = "#FF0000";
	}
}

function doOut(el) {
	cal_Day = el.title;

	if (cal_Day.length > 7) {
		el.style.borderColor = "#FFFFFF";
	}
}

function day2(d) {	// 2자리 숫자료 변경
	var str = new String();
	
	if (parseInt(d) < 10) {
		str = "0" + parseInt(d);
	} else {
		str = "" + parseInt(d);
	}
	return str;
}


//----------------------------------
//	일달력 년도리스트에서 년도 선택
//----------------------------------
function fnChangeYearD(sYear,sMonth,sDay){
	Show_cal(sYear, sMonth, sDay);
}

function fnChangeYearDHotel(sYear,sMonth,sDay){
	Show_calHotel(sYear, sMonth, sDay);
}

function fnChangeYearDIndex(sYear,sMonth,sDay){
	Show_calIndex(sYear, sMonth, sDay);
}

//----------------------------------
//	월달력 년도리스트에서 년도 선택
//----------------------------------
function fnChangeYearM(sYear,sMonth){
	Show_calHotel_M(sYear, sMonth);
}


/**
	HTML 개체용 유틸리티 함수
**/
function GetObjectTop(obj)
{
	if (obj.offsetParent == document.body)
		return obj.offsetTop;
	else
		return obj.offsetTop + GetObjectTop(obj.offsetParent);
}

function GetObjectLeft(obj)
{
	if (obj.offsetParent == document.body)
		return obj.offsetLeft;
	else
		return obj.offsetLeft + GetObjectLeft(obj.offsetParent);
}

// 날짜 차이 구하는 함수
function getDayInterval(time1,time2) {
    var date1 = toTimeObject(time1);
    var date2 = toTimeObject(time2);
    var day   = 1000 * 3600 * 24; //24시간

    return parseInt((date2 - date1) / day, 10);
}

//Time 스트링을 자바스크립트 Date 객체로 변환
function toTimeObject(time) { //parseTime(time)
    var year  = time.substr(0,4);
    var month = time.substr(4,2) - 1; // 1월=0,12월=11
    var day   = time.substr(6,2);
    var hour  = time.substr(8,2);
    var min   = time.substr(10,2);

    return new Date(year,month,day,hour,min);
}